<?php

namespace App\Jobs;

use Carbon\Carbon;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Log;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Support\Facades\Storage;
use GuzzleHttp\Client;

class AddImageToLocalJob implements ShouldQueue
{
	use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
	
	public $path;
	
	public function __construct($path)
	{
		$this->path = $path;
	}
	
	public function handle()
	{
        $path = $this->path;
        $client = new Client();
        $fileNameArr = explode('/',$path);

        $fileName = end($fileNameArr);

        $response = $client->request('GET', Storage::url($path), [

            ]);

       
		Storage::disk('public')->put($fileName,$response->getBody());
		
	}
}
